﻿<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>
  
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Class Util
   </title>
    <meta name="viewport" content="width=device-width">
    <meta name="title" content="Class Util
   ">
    <meta name="generator" content="docfx 2.42.4.0">
    
    <link rel="shortcut icon" href="../favicon.ico">
    <link rel="stylesheet" href="../styles/docfx.vendor.css">
    <link rel="stylesheet" href="../styles/docfx.css">
    <link rel="stylesheet" href="../styles/main.css">
    <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"> 
    <meta property="docfx:navrel" content="../toc.html">
    <meta property="docfx:tocrel" content="toc.html">
    
    
    
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
  <link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
  <script defer="" src="https://code.getmdl.io/1.3.0/material.min.js"></script>
  </head>  <body data-spy="scroll" data-target="#affix" data-offset="120">
    <div id="wrapper">
      <header>
        
        <nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation">
          <div class="container">
            <div class="navbar-header">
              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
              </button>
              
              <a class="navbar-brand" href="../index.html">
                <img id="logo" class="svg" src="../logo.svg" alt="">
              </a>
            </div>
            <div class="collapse navbar-collapse" id="navbar">
              <form class="navbar-form navbar-right" role="search" id="search">
                <div class="form-group">
                  <input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
                </div>
              </form>
            </div>
          </div>
        </nav>
        
        <div class="subnav navbar navbar-default">
          <div class="container hide-when-search" id="breadcrumb">
            <ul class="breadcrumb">
              <li></li>
            </ul>
          </div>
        </div>
      </header>
      <div role="main" class="container body-content hide-when-search">
        
        <div class="sidenav hide-when-search">
          <a class="btn toc-toggle collapse" data-toggle="collapse" href="#sidetoggle" aria-expanded="false" aria-controls="sidetoggle">Show / Hide Table of Contents</a>
          <div class="sidetoggle collapse" id="sidetoggle">
            <div id="sidetoc"></div>
          </div>
        </div>
        <div class="article row grid-right">
          <div class="col-md-10">
            <article class="content wrap" id="_content" data-uid="Keras.Utils.Util">
  
  
  <h1 id="Keras_Utils_Util" data-uid="Keras.Utils.Util" class="text-break">Class Util
  </h1>
  <div class="markdown level0 summary"></div>
  <div class="markdown level0 conceptual"></div>
  <div class="inheritance">
    <h5>Inheritance</h5>
    <div class="level0"><span class="xref">System.Object</span></div>
    <div class="level1"><a class="xref" href="Keras.Keras.html">Keras</a></div>
    <div class="level2"><a class="xref" href="Keras.Base.html">Base</a></div>
    <div class="level3"><span class="xref">Util</span></div>
  </div>
  <div classs="implements">
    <h5>Implements</h5>
    <div><span class="xref">System.IDisposable</span></div>
  </div>
  <div class="inheritedMembers">
    <h5>Inherited Members</h5>
    <div>
      <a class="xref" href="Keras.Base.html#Keras_Base_Parameters">Base.Parameters</a>
    </div>
    <div>
      <a class="xref" href="Keras.Base.html#Keras_Base_None">Base.None</a>
    </div>
    <div>
      <a class="xref" href="Keras.Base.html#Keras_Base_Init">Base.Init()</a>
    </div>
    <div>
      <a class="xref" href="Keras.Base.html#Keras_Base_ToPython">Base.ToPython()</a>
    </div>
    <div>
      <a class="xref" href="Keras.Base.html#Keras_Base_InvokeStaticMethod_System_Object_System_String_System_Collections_Generic_Dictionary_System_String_System_Object__">Base.InvokeStaticMethod(Object, String, Dictionary&lt;String, Object&gt;)</a>
    </div>
    <div>
      <a class="xref" href="Keras.Base.html#Keras_Base_InvokeMethod_System_String_System_Collections_Generic_Dictionary_System_String_System_Object__">Base.InvokeMethod(String, Dictionary&lt;String, Object&gt;)</a>
    </div>
    <div>
      <a class="xref" href="Keras.Base.html#Keras_Base_Item_System_String_">Base.Item[String]</a>
    </div>
    <div>
      <a class="xref" href="Keras.Keras.html#Keras_Keras_Instance">Keras.Instance</a>
    </div>
    <div>
      <a class="xref" href="Keras.Keras.html#Keras_Keras_keras">Keras.keras</a>
    </div>
    <div>
      <a class="xref" href="Keras.Keras.html#Keras_Keras_keras2onnx">Keras.keras2onnx</a>
    </div>
    <div>
      <a class="xref" href="Keras.Keras.html#Keras_Keras_tfjs">Keras.tfjs</a>
    </div>
    <div>
      <a class="xref" href="Keras.Keras.html#Keras_Keras_Dispose">Keras.Dispose()</a>
    </div>
    <div>
      <a class="xref" href="Keras.Keras.html#Keras_Keras_ToTuple_System_Array_">Keras.ToTuple(Array)</a>
    </div>
    <div>
      <a class="xref" href="Keras.Keras.html#Keras_Keras_ToList_System_Array_">Keras.ToList(Array)</a>
    </div>
    <div>
      <span class="xref">System.Object.Equals(System.Object)</span>
    </div>
    <div>
      <span class="xref">System.Object.Equals(System.Object, System.Object)</span>
    </div>
    <div>
      <span class="xref">System.Object.GetHashCode()</span>
    </div>
    <div>
      <span class="xref">System.Object.GetType()</span>
    </div>
    <div>
      <span class="xref">System.Object.MemberwiseClone()</span>
    </div>
    <div>
      <span class="xref">System.Object.ReferenceEquals(System.Object, System.Object)</span>
    </div>
    <div>
      <span class="xref">System.Object.ToString()</span>
    </div>
  </div>
  <h6><strong>Namespace</strong>: <a class="xref" href="Keras.Utils.html">Keras.Utils</a></h6>
  <h6><strong>Assembly</strong>: Keras.dll</h6>
  <h5 id="Keras_Utils_Util_syntax">Syntax</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public class Util : Base, IDisposable</code></pre>
  </div>
  <h3 id="methods">Methods
  </h3>
  <span class="small pull-right mobile-hide">
    <span class="divider">|</span>
    <a href="https://github.com/SciSharp/Keras.NET/new/master/apiSpec/new?filename=Keras_Utils_Util_MultiGPUModel_Keras_Models_BaseModel_System_Int32___System_Boolean_System_Boolean_.md&amp;value=---%0Auid%3A%20Keras.Utils.Util.MultiGPUModel(Keras.Models.BaseModel%2CSystem.Int32%5B%5D%2CSystem.Boolean%2CSystem.Boolean)%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
  </span>
  <span class="small pull-right mobile-hide">
    <a href="https://github.com/SciSharp/Keras.NET/blob/master/Keras/Utils/Utils.cs/#L22">View Source</a>
  </span>
  <a id="Keras_Utils_Util_MultiGPUModel_" data-uid="Keras.Utils.Util.MultiGPUModel*"></a>
  <h4 id="Keras_Utils_Util_MultiGPUModel_Keras_Models_BaseModel_System_Int32___System_Boolean_System_Boolean_" data-uid="Keras.Utils.Util.MultiGPUModel(Keras.Models.BaseModel,System.Int32[],System.Boolean,System.Boolean)">MultiGPUModel(BaseModel, Int32[], Boolean, Boolean)</h4>
  <div class="markdown level1 summary"><p>Replicates a model on different GPUs.    Specifically, this function implements single-machine multi-GPU data parallelism.It works in the following way:
Divide the model's input(s) into multiple sub-batches. Apply a model copy on each sub-batch.Every model copy is executed on a dedicated GPU.
Concatenate the results(on CPU) into one big batch.
E.g. if your batch_size is 64 and you use gpus = 2, then we will divide the input into 2 sub-batches of 32 samples, process each sub-batch on one GPU, then return the full batch of 64 processed samples.
This induces quasi-linear speedup on up to 8 GPUs. This function is only available with the TensorFlow backend for the time being.</p>
</div>
  <div class="markdown level1 conceptual"></div>
  <h5 class="decalaration">Declaration</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static BaseModel MultiGPUModel(BaseModel model, int[] gpus, bool cpu_merge = true, bool cpu_relocation = false)</code></pre>
  </div>
  <h5 class="parameters">Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><a class="xref" href="Keras.Models.BaseModel.html">BaseModel</a></td>
        <td><span class="parametername">model</span></td>
        <td><p>A Keras model instance. To avoid OOM errors, this model could have been built on CPU, for instance.</p>
</td>
      </tr>
      <tr>
        <td><span class="xref">System.Int32</span>[]</td>
        <td><span class="parametername">gpus</span></td>
        <td><p>Integer &gt;= 2 or list of integers, number of GPUs or list of GPU IDs on which to create model replicas.</p>
</td>
      </tr>
      <tr>
        <td><span class="xref">System.Boolean</span></td>
        <td><span class="parametername">cpu_merge</span></td>
        <td><p>Integer &gt;= 2 or list of integers, number of GPUs or list of GPU IDs on which to create model replicas.</p>
</td>
      </tr>
      <tr>
        <td><span class="xref">System.Boolean</span></td>
        <td><span class="parametername">cpu_relocation</span></td>
        <td><p>A boolean value to identify whether to create the model's weights under the scope of the CPU. If the model is not defined under any preceding device scope, you can still rescue it by activating this option.</p>
</td>
      </tr>
    </tbody>
  </table>
  <h5 class="returns">Returns</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><a class="xref" href="Keras.Models.BaseModel.html">BaseModel</a></td>
        <td><p>A Keras Model instance which can be used just like the initial model argument, but which distributes its workload on multiple GPUs.</p>
</td>
      </tr>
    </tbody>
  </table>
  <span class="small pull-right mobile-hide">
    <span class="divider">|</span>
    <a href="https://github.com/SciSharp/Keras.NET/new/master/apiSpec/new?filename=Keras_Utils_Util_Normalize_Numpy_NDarray_System_Int32_System_Int32_.md&amp;value=---%0Auid%3A%20Keras.Utils.Util.Normalize(Numpy.NDarray%2CSystem.Int32%2CSystem.Int32)%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
  </span>
  <span class="small pull-right mobile-hide">
    <a href="https://github.com/SciSharp/Keras.NET/blob/master/Keras/Utils/Utils.cs/#L48">View Source</a>
  </span>
  <a id="Keras_Utils_Util_Normalize_" data-uid="Keras.Utils.Util.Normalize*"></a>
  <h4 id="Keras_Utils_Util_Normalize_Numpy_NDarray_System_Int32_System_Int32_" data-uid="Keras.Utils.Util.Normalize(Numpy.NDarray,System.Int32,System.Int32)">Normalize(NDarray, Int32, Int32)</h4>
  <div class="markdown level1 summary"><p>Normalizes a Numpy array.</p>
</div>
  <div class="markdown level1 conceptual"></div>
  <h5 class="decalaration">Declaration</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static NDarray Normalize(NDarray y, int axis = -1, int order = 2)</code></pre>
  </div>
  <h5 class="parameters">Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="xref">Numpy.NDarray</span></td>
        <td><span class="parametername">y</span></td>
        <td><p>Numpy array to normalize.</p>
</td>
      </tr>
      <tr>
        <td><span class="xref">System.Int32</span></td>
        <td><span class="parametername">axis</span></td>
        <td><p>axis along which to normalize.</p>
</td>
      </tr>
      <tr>
        <td><span class="xref">System.Int32</span></td>
        <td><span class="parametername">order</span></td>
        <td><p>Normalization order (e.g. 2 for L2 norm).</p>
</td>
      </tr>
    </tbody>
  </table>
  <h5 class="returns">Returns</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="xref">Numpy.NDarray</span></td>
        <td></td>
      </tr>
    </tbody>
  </table>
  <span class="small pull-right mobile-hide">
    <span class="divider">|</span>
    <a href="https://github.com/SciSharp/Keras.NET/new/master/apiSpec/new?filename=Keras_Utils_Util_PlotModel_Keras_Models_BaseModel_System_String_System_Boolean_System_Boolean_System_String_System_Boolean_System_Int32_.md&amp;value=---%0Auid%3A%20Keras.Utils.Util.PlotModel(Keras.Models.BaseModel%2CSystem.String%2CSystem.Boolean%2CSystem.Boolean%2CSystem.String%2CSystem.Boolean%2CSystem.Int32)%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
  </span>
  <span class="small pull-right mobile-hide">
    <a href="https://github.com/SciSharp/Keras.NET/blob/master/Keras/Utils/Utils.cs/#L64">View Source</a>
  </span>
  <a id="Keras_Utils_Util_PlotModel_" data-uid="Keras.Utils.Util.PlotModel*"></a>
  <h4 id="Keras_Utils_Util_PlotModel_Keras_Models_BaseModel_System_String_System_Boolean_System_Boolean_System_String_System_Boolean_System_Int32_" data-uid="Keras.Utils.Util.PlotModel(Keras.Models.BaseModel,System.String,System.Boolean,System.Boolean,System.String,System.Boolean,System.Int32)">PlotModel(BaseModel, String, Boolean, Boolean, String, Boolean, Int32)</h4>
  <div class="markdown level1 summary"><p>Converts a Keras model to dot format and save to a file.</p>
</div>
  <div class="markdown level1 conceptual"></div>
  <h5 class="decalaration">Declaration</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static void PlotModel(BaseModel model, string to_file = &quot;model.png&quot;, bool show_shapes = false, bool show_layer_names = true, string rankdir = &quot;TB&quot;, bool expand_nested = false, int dpi = 96)</code></pre>
  </div>
  <h5 class="parameters">Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><a class="xref" href="Keras.Models.BaseModel.html">BaseModel</a></td>
        <td><span class="parametername">model</span></td>
        <td><p>A Keras model instance</p>
</td>
      </tr>
      <tr>
        <td><span class="xref">System.String</span></td>
        <td><span class="parametername">to_file</span></td>
        <td><p>File name of the plot image.</p>
</td>
      </tr>
      <tr>
        <td><span class="xref">System.Boolean</span></td>
        <td><span class="parametername">show_shapes</span></td>
        <td><p>whether to display shape information.</p>
</td>
      </tr>
      <tr>
        <td><span class="xref">System.Boolean</span></td>
        <td><span class="parametername">show_layer_names</span></td>
        <td><p>whether to display layer names.</p>
</td>
      </tr>
      <tr>
        <td><span class="xref">System.String</span></td>
        <td><span class="parametername">rankdir</span></td>
        <td></td>
      </tr>
      <tr>
        <td><span class="xref">System.Boolean</span></td>
        <td><span class="parametername">expand_nested</span></td>
        <td><p>whether to expand nested models into clusters.</p>
</td>
      </tr>
      <tr>
        <td><span class="xref">System.Int32</span></td>
        <td><span class="parametername">dpi</span></td>
        <td><p>dot DPI.</p>
</td>
      </tr>
    </tbody>
  </table>
  <span class="small pull-right mobile-hide">
    <span class="divider">|</span>
    <a href="https://github.com/SciSharp/Keras.NET/new/master/apiSpec/new?filename=Keras_Utils_Util_ToCategorical_Numpy_NDarray_System_Nullable_System_Int32__System_String_.md&amp;value=---%0Auid%3A%20Keras.Utils.Util.ToCategorical(Numpy.NDarray%2CSystem.Nullable%7BSystem.Int32%7D%2CSystem.String)%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
  </span>
  <span class="small pull-right mobile-hide">
    <a href="https://github.com/SciSharp/Keras.NET/blob/master/Keras/Utils/Utils.cs/#L36">View Source</a>
  </span>
  <a id="Keras_Utils_Util_ToCategorical_" data-uid="Keras.Utils.Util.ToCategorical*"></a>
  <h4 id="Keras_Utils_Util_ToCategorical_Numpy_NDarray_System_Nullable_System_Int32__System_String_" data-uid="Keras.Utils.Util.ToCategorical(Numpy.NDarray,System.Nullable{System.Int32},System.String)">ToCategorical(NDarray, Nullable&lt;Int32&gt;, String)</h4>
  <div class="markdown level1 summary"><p>Converts a class vector (integers) to binary class matrix. E.g. for use with categorical_crossentropy.</p>
</div>
  <div class="markdown level1 conceptual"></div>
  <h5 class="decalaration">Declaration</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static NDarray ToCategorical(NDarray y, int? num_classes = default(int? ), string dtype = &quot;float32&quot;)</code></pre>
  </div>
  <h5 class="parameters">Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="xref">Numpy.NDarray</span></td>
        <td><span class="parametername">y</span></td>
        <td><p>class vector to be converted into a matrix (integers from 0 to num_classes).</p>
</td>
      </tr>
      <tr>
        <td><span class="xref">System.Nullable</span>&lt;<span class="xref">System.Int32</span>&gt;</td>
        <td><span class="parametername">num_classes</span></td>
        <td><p>total number of classes.</p>
</td>
      </tr>
      <tr>
        <td><span class="xref">System.String</span></td>
        <td><span class="parametername">dtype</span></td>
        <td><p>The data type expected by the input, as a string (float32, float64, int32...)</p>
</td>
      </tr>
    </tbody>
  </table>
  <h5 class="returns">Returns</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="xref">Numpy.NDarray</span></td>
        <td><p>A binary matrix representation of the input. The classes axis is placed last.</p>
</td>
      </tr>
    </tbody>
  </table>
  <h3 id="implements">Implements</h3>
  <div>
      <span class="xref">System.IDisposable</span>
  </div>
</article>
          </div>
          
          <div class="hidden-sm col-md-2" role="complementary">
            <div class="sideaffix">
              <div class="contribution">
                <ul class="nav">
                  <li>
                    <a href="https://github.com/SciSharp/Keras.NET/new/master/apiSpec/new?filename=Keras_Utils_Util.md&amp;value=---%0Auid%3A%20Keras.Utils.Util%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A" class="contribution-link">Improve this Doc</a>
                  </li>
                  <li>
                    <a href="https://github.com/SciSharp/Keras.NET/blob/master/Keras/Utils/Utils.cs/#L8" class="contribution-link">View Source</a>
                  </li>
                </ul>
              </div>
              <nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
              <!-- <p><a class="back-to-top" href="#top">Back to top</a><p> -->
              </nav>
            </div>
          </div>
        </div>
      </div>
      
      <footer>
        <div class="grad-bottom"></div>
        <div class="footer">
          <div class="container">
            <span class="pull-right">
              <a href="#top">Back to top</a>
            </span>
            
            <span>Generated by <strong>DocFX</strong></span>
          </div>
        </div>
      </footer>
    </div>
    
    <script type="text/javascript" src="../styles/docfx.vendor.js"></script>
    <script type="text/javascript" src="../styles/docfx.js"></script>
    <script type="text/javascript" src="../styles/main.js"></script>
  </body>
</html>
